<template>
  <el-form ref="form" :rules="rules" style="padding-top: 10px;" :model="form" label-width="80px">
    <el-form-item label="机构名称" prop="name">
      <el-input v-model="form.name" />
    </el-form-item>
    <el-row>
      <el-col :span="12">
        <el-form-item label="机构类型" prop="type">
          <el-select v-model="form.type" style="width: 100%;" placeholder="请选择活动区域">
            <el-option v-for="item in orgTypes" :key="item.name" :label="item.name" :value="item.value" />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="机构编号" prop="number">
          <el-input v-model="form.number" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="传真">
          <el-input v-model="form.fax" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="联系电话">
          <el-input v-model="form.phone" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="电子邮箱">
          <el-input v-model="form.email" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="邮政编码">
          <el-input v-model="form.postCode" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="QQ">
          <el-input v-model="form.qq" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="排序">
          <el-input v-model="form.sort" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="启用">
          <el-switch
            v-model="form.enable"
            active-color="#13ce66"
            inactive-color="#ff4949"
          />
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item label="地址">
      <el-input v-model="form.address" />
    </el-form-item>
    <el-form-item label="机构职责">
      <el-input v-model="form.description" type="textarea" />
    </el-form-item>
    <el-form-item label="备注">
      <el-input v-model="form.remark" type="textarea" />
    </el-form-item>
  </el-form>
</template>

<script>
import { orgTypes } from '@/utils/dicData'
export default {
  name: 'ManageDetail',
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    },
    type: {
      type: String,
      default: 'add'
    }
  },
  data() {
    return {
      orgTypes,
      form: {
        name: '',
        number: '',
        type: '',
        fax: '',
        phone: '',
        email: '',
        postCode: '',
        qq: '',
        enable: true,
        address: '',
        description: '',
        remark: '',
        sort: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入机构名称', trigger: 'change' }
        ],
        number: [
          { required: true, message: '请选择机构编码', trigger: 'change' }
        ],
        type: [
          { required: true, message: '请选择机构类型', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    data: {
      handler(newData, oldData) {
        Object.keys(this.form).forEach(key => {
          const val = newData[key]
          this.form[key] = val
        })
      },
      deep: true
    }
  },
  methods: {
    validateForm(fn) {
      this.$refs.form.validate((valid) => {
        fn(valid)
      })
    },
    resetForm() {
      this.$refs.form.resetFields()
    }

  }
}
</script>

<style lang="scss" scoped>

</style>
